package drds.configuration.mvc.render;


import drds.configuration.common.Constants;
import drds.configuration.mvc.core.ActionContext;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HttpRender extends Render {

    private String url;

    public HttpRender(String url) {
        if (!url.contains("http")) {
            throw new RuntimeException("url is not contains http");
        }
        this.url = url;
    }

    @Override
    public void render() {
        HttpServletResponse response = ActionContext.getResponse();
        try {
            response.sendRedirect(url);
            if (Constants.devMode) {
                logger.info("url:" + url);
            }
        } catch (IOException e) {
            throw new RenderException(e);
        }
    }
}
